<template>
  <div>
    <el-card :bordered="false" shadow="never" class="ivu-mt" :body-style="{ padding: 0 }">
      <div class="padding-add">
        <el-form
          ref="userFrom"
          :model="userFrom"
          label-width="80px"
          label-position="right"
          @submit.native.prevent
          inline
        >
          <div class="acea-row search-form" v-if="!collapse">
            <div>
              <el-form-item label="用户昵称:" label-for="user_name">
                <el-input clearable placeholder="请输入内容" v-model="userFrom.userName" class="form_content_width" />
              </el-form-item>
              <el-form-item label="注册方式：" label-for="regType">
                <el-select
                  class="w200"
                  :popper-append-to-body="false"
                  v-model="userFrom.regType"
                  placeholder="请选择"
                  @change="chosess"
                >
                  <el-option v-for="item in options1" :key="item.id" :label="item.name" :value="item.id"></el-option>
                </el-select>
              </el-form-item>

              <el-form-item label="证件证号:" label-for="passportNumber">
                <el-input
                  clearable
                  placeholder="请输入内容"
                  v-model="userFrom.passportNumber"
                  class="form_content_width"
                />
              </el-form-item>
              <el-form-item label="商家所在地:" label-for="nick_name">
                <el-cascader
                  class="w200"
                  :props="props3"
                  v-model="userFrom.shopCityId"
                  @change="handleChange"
                  placeholder="请选择"
                ></el-cascader>
              </el-form-item>
            </div>
            <el-form-item class="search-form-sub">
              <el-button type="primary" @click="userSearchs">搜索</el-button>
              <el-button class="ResetSearch" @click="reset('userFrom')">重置</el-button>
              <a class="ivu-ml-8 font12 ml10" @click="collapse = !collapse">
                <template v-if="!collapse"> 展开 <i class="el-icon-arrow-down" /> </template>
                <template v-else> 收起 <i class="el-icon-arrow-up" /> </template>
              </a>
            </el-form-item>
          </div>
          <div v-if="collapse" class="acea-row search-form">
            <div class="search-form-box">
              <el-form-item label="用户昵称:" label-for="user_name">
                <el-input clearable placeholder="请输入内容" v-model="userFrom.userName" class="form_content_width" />
              </el-form-item>
              <el-form-item label="注册方式：" label-for="regType">
                <el-select
                  class="w200"
                  :popper-append-to-body="false"
                  v-model="userFrom.regType"
                  placeholder="请选择"
                  @change="chosess"
                >
                  <el-option v-for="item in options1" :key="item.id" :label="item.name" :value="item.id"></el-option>
                </el-select>
              </el-form-item>

              <el-form-item label="证件证号:" label-for="passportNumber">
                <el-input
                  clearable
                  placeholder="请输入内容"
                  v-model="userFrom.passportNumber"
                  class="form_content_width"
                />
              </el-form-item>
              <el-form-item label="商家所在地:" label-for="nick_name">
                <el-cascader
                  class="w200"
                  :props="props3"
                  v-model="userFrom.shopCityId"
                  @change="handleChange"
                  placeholder="请选择"
                ></el-cascader>
              </el-form-item>
              <el-form-item label="状态:" label-for="status">
                <el-select :popper-append-to-body="false" v-model="userFrom.status" placeholder="请选择">
                  <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="托管:" label-for="accountType">
                <el-select :popper-append-to-body="false" v-model="userFrom.accountType" placeholder="请选择">
                  <el-option
                    v-for="item in optionsAccountType"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="商家名称:" label-for="user_name">
                <el-input
                  clearable
                  placeholder="公司名称|真实姓名"
                  v-model="userFrom.shopName"
                  class="form_content_width"
                />
              </el-form-item>
              <el-form-item label="平台来源:" label-for="fromAppType">
                <el-select :popper-append-to-body="false" v-model="userFrom.fromAppType" placeholder="请选择">
                  <el-option
                    v-for="item in options3"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>

              <el-form-item label="平台来源:" label-for="fromAppType">
                <el-select :popper-append-to-body="false" v-model="userFrom.fromAppType" placeholder="请选择">
                  <el-option
                    v-for="item in options3"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>

              <el-form-item label="是否商家:" label-for="shopContactName">
                <el-select
                  class="w200"
                  :popper-append-to-body="false"
                  v-model="userFrom.isMerchant"
                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in options2"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>

              <el-form-item label="未登录时长:" label-for="shopContactName">
                <el-select :popper-append-to-body="false" v-model="userFrom.onlineStatus" placeholder="请选择">
                  <el-option
                    v-for="item in options8"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>

              <el-form-item label="商家广告栏:" label-for="shopRecommendStatus">
                <el-select :popper-append-to-body="false" v-model="userFrom.shopRecommendStatus" placeholder="请选择">
                  <el-option
                    v-for="item in options7"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>

              <el-form-item label="商家联系号码:" label-for="shopContactTel" label-width="120px">
                <el-input
                  clearable
                  placeholder="请输入内容"
                  v-model="userFrom.shopContactTel"
                  class="form_content_width"
                />
              </el-form-item>

              <el-form-item label="行业分类:" label-for="userCategoryId">
                <el-cascader
                  class="w200"
                  v-model="userFrom.userCategoryId"
                  :options="options5"
                  @change="handleChange"
                  :props="props1"
                ></el-cascader>
              </el-form-item>

              <el-form-item label="产品分类:" label-for="userCategoryId">
                <el-cascader
                  :props="props2"
                  v-model="userFrom.productCategoryId"
                  @change="handleChange"
                  placeholder="请选择"
                  :options="options6"
                ></el-cascader>
              </el-form-item>

              <el-form-item label="登录账号:" label-for="shopContactTel" v-if="userFrom.originSite == 'cn'">
                <el-input
                  clearable
                  placeholder="请输入内容"
                  v-model="userFrom.loginAccount"
                  class="form_content_width"
                />
              </el-form-item>

              <el-form-item :label="userFrom.originSite == 'cn' ? '登录手机' : '联系电话'" label-for="shopContactTel">
                <el-input
                  clearable
                  placeholder="请输入内容"
                  v-model="userFrom.searchPhone"
                  class="form_content_width"
                />
              </el-form-item>

              <el-form-item label="国家:" label-for="userCategoryId" v-if="userFrom.originSite == 'com'">
                <el-select
                  class="w200"
                  :popper-append-to-body="false"
                  v-model="userFrom.countryCode"
                  placeholder="请选择"
                >
                  <el-option v-for="item in options4" :key="item.id" :label="item.zh_name" :value="item.id"></el-option>
                </el-select>
              </el-form-item>

              <el-form-item label="是否有团队:" label-for="userCategoryId" v-if="userFrom.originSite == 'cn'">
                <el-select :popper-append-to-body="false" v-model="is_team" placeholder="请选择">
                  <el-option
                    v-for="item in options2"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>

              <el-form-item label="创建时间:" label-for="date_time">
                <el-date-picker
                  v-model="userFrom.dateTime"
                  type="daterange"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                >
                </el-date-picker>
              </el-form-item>
            </div>

            <el-form-item class="search-form-sub">
              <el-button type="primary" label="default" @click="userSearchs">搜索</el-button>
              <el-button class="ResetSearch" @click="reset('userFrom')">重置</el-button>
              <a class="ivu-ml-8 font12 ml10" @click="collapse = !collapse">
                <template v-if="!collapse"> 展开 <i class="el-icon-arrow-down" /> </template>
                <template v-else> 收起 <i class="el-icon-arrow-up" /> </template>
              </a>
            </el-form-item>
          </div>
        </el-form>
      </div>
    </el-card>
    <el-card :bordered="false" shadow="never" class="ivu-mt mt16" :body-style="{ padding: '0 20px 20px' }">
      <el-tabs v-model="userFrom.user_type" @tab-click="onClickTab">
        <el-tab-pane :label="item.name" :name="item.type" v-for="(item, index) in headeNum" :key="index" />
      </el-tabs>
      <el-tabs v-model="userFrom.user_type1" @tab-click="onClickTab">
        <el-tab-pane :label="item.name" :name="item.type" v-for="(item, index) in headeNum1" :key="index" />
      </el-tabs>
      <el-tabs v-model="userFrom.user_type2" @tab-click="onClickTab">
        <el-tab-pane :label="item.name" :name="item.type" v-for="(item, index) in headeNum2" :key="index" />
      </el-tabs>
      <el-table
        :data="userLists"
        class="mt16"
        ref="table"
        highlight-current-row
        v-loading="loading"
        empty-text="暂无数据"
        no-filtered-userFrom-text="暂无筛选结果"
        @sort-change="sortChanged"
        @select="handleSelectRow"
        @select-all="handleSelectAll"
      >
        <el-table-column label="选中" width="60" fixed>
          <template slot-scope="scope">
            <el-checkbox v-model="scope.row.checked" @change="checkedSingleData(scope.row)"></el-checkbox>
          </template>
        </el-table-column>
        <el-table-column label="ID" min-width="35">
          <template slot-scope="scope">
            <span>{{ scope.row.id }}</span>
          </template>
        </el-table-column>
        <el-table-column label="头像" min-width="30">
          <template slot-scope="scope">
            <div class="tabBox2_img" v-viewer>
              <img v-lazy="scope.row.user_avatar ? imgOssUrl + scope.row.user_avatar : imgUrl" />
            </div>
          </template>
        </el-table-column>
       <el-table-column label="用户信息" min-width="150">
          <template slot-scope="scope">
            <div>用户昵称:{{ scope.row.nick }}</div>
            <div v-if="scope.row.phone && userFrom.originSite == 'cn'">登录手机:{{ scope.row.phone }}</div>
            <div v-if="scope.row.username">登录账号:{{ scope.row.username }}</div>
            <div v-if="scope.row.email">登录邮箱:{{ scope.row.email }}</div>
            <div v-if="scope.row.phone && userFrom.originSite == 'com'">联系电话:{{ scope.row.phone }}</div>
            <div v-if="scope.row.online_status == 1">在线</div>
            <div v-if="scope.row.online_status == 2">超过1周末登录</div>
            <div v-if="scope.row.online_status == 3">超过1月未登录</div>
            <div v-if="scope.row.online_status == 4">长久未登录</div>
          </template>
        </el-table-column> 
        <el-table-column label="平台来源" min-width="60">
          <template slot-scope="scope">
            <span v-if="scope.row.reg_app_type == 0">后台注册</span>
            <span v-else-if="scope.row.reg_app_type == 1">国内PC</span>
            <span v-else-if="scope.row.reg_app_type == 2">国内H5</span>
            <span v-else-if="scope.row.reg_app_type == 4">微信小程序</span>
            <span v-else-if="scope.row.reg_app_type == 8">国内APP</span>
            <span v-else-if="scope.row.reg_app_type == 16">国内APP</span>
            <span v-else-if="scope.row.reg_app_type == 32">国外PC</span>
            <span v-else-if="scope.row.reg_app_type == 64">国外APP</span>
            <span v-else-if="scope.row.reg_app_type == 128">国外APP</span>
          </template>
        </el-table-column>
        <el-table-column label="注册方式" min-width="80">
          <template slot-scope="scope">
            <span v-if="scope.row.reg_type == 0">后台注册</span>
            <span v-else-if="scope.row.reg_type == 1">手机号</span>
            <span v-else-if="scope.row.reg_type == 2">邮箱</span>
            <span v-else-if="scope.row.reg_type == 3">微信</span>
            <span v-else-if="scope.row.reg_type == 4">支付宝</span>
            <span v-else-if="scope.row.reg_type == 5">QQ</span>
            <span v-else-if="scope.row.reg_type == 6">账号</span>
            <span v-else-if="scope.row.reg_type == 7">Google</span>
          </template>
        </el-table-column>
        <el-table-column label="商家信息" min-width="120">
          <template slot-scope="scope">
            <div class="textal" v-if="scope.row.shop_name">
              {{ scope.row.auth_type == '1' ? '真实姓名' : '公司名称' }}:{{ scope.row.shop_name }}
            </div>
            <div class="textal" v-if="scope.row.corporation">联系人:{{ scope.row.corporation }}</div>
            <div class="textal" v-if="scope.row.tel">联系电话:{{ scope.row.tel }}</div>
            <div class="textal" v-if="scope.row.country_name">所在地:{{ scope.row.country_name }}</div>
          </template>
        </el-table-column>
        <el-table-column label="商家身份类型" min-width="50">
          <template slot-scope="scope">
            <div class="textal" v-if="scope.row.auth_type > 0 && activateS == -1">
              身份类型:{{ scope.row.auth_type == '1' ? '个人身份' : scope.row.auth_type == '2' ? '企业身份' : '' }}
            </div>
            <div class="textal" v-if="scope.row.user_category_names.length > 0">
              行业分类:
              <span v-for="(item, index) in scope.row.user_category_names" :key="index">
                {{ item }} <i v-if="scope.row.user_category_names.length - 1 != index"> ,</i>
              </span>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="score" label="运营权重分" v-if="activateS == 2" width="180">
          <template slot-scope="scope">{{ scope.row.user_weight }}</template>
        </el-table-column>

        <el-table-column prop="score" label="平台权重分" v-if="activateS == 2" width="180">
          <template slot-scope="scope">
            <el-input-number
              size="small"
              v-model="scope.row.custom_weight"
              @change="bianji2(scope.row, scope.row.custom_weight)"
              :max="9999"
              label="描述文字"
            ></el-input-number>
          </template>
        </el-table-column>
        <el-table-column prop="score" label="排名总分" v-if="activateS == 2" width="180">
          <template slot-scope="scope">{{ scope.row.weight }}</template>
        </el-table-column>
        <el-table-column prop="last_login_time" width="280" label="时间">
          <template slot-scope="{ row }">
            <div class="textal">最后登录时间:{{ row.last_login_time }}</div>
            <div class="textal">创建时间:{{ row.create_time }}</div>
            <div class="textal">审核时间:{{ row.audit_time }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="status" label="启用状态">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.status"
              :active-value="1"
              @change="bianji1(scope.row)"
              :inactive-value="0"
            ></el-switch>
          </template>
        </el-table-column>

        <el-table-column prop="favorites_num" label="邀请人" width="200">
          <template slot-scope="scope">
            <div class="textal" v-if="scope.row.inviter_info.nick">
              昵称: <span>{{ scope.row.inviter_info.nick }}</span>
            </div>
            <div class="textal" v-if="scope.row.inviter_info.phone">
              手机号: <span>{{ scope.row.inviter_info.phone }}</span>
            </div>
          </template>
        </el-table-column> 
        <el-table-column label="操作" fixed="right" width="120">
          <template slot-scope="scope">
            <template>
              <a @click="userDetail(scope.row)">详情</a>

              <el-divider direction="vertical"></el-divider>
              <a @click="userDetail(scope.row)">操作</a>
            </template>
          </template>
        </el-table-column>
      </el-table>
      <div class="acea-row row-right page">
        <pagination
          v-if="total"
          :total="total"
          :page.sync="userFrom.page"
          :limit.sync="userFrom.limit"
          @pagination="pageChange"
        />
      </div>
    </el-card>
  </div>
</template>
<script>
import {
  getShopAuth,
  getProvinceFn,
  getRegTypeList,
  getUserCategory,
  getProductCategory,
  getCountryCode,
  getUserList
} from '@/api/all';
export default {
  name: '',
  components: {},
  data() {
    let that = this;
    return {
      imgUrl: require('@/assets/images/ren.png'),
      userFrom: {
        userName: '',
        regType: '',
        passportNumber: '',
        nickName: '',
        dateTime: '',
        user_type: '',
        user_type1: '',
        user_type2: '',
        page: 1,
        limit: 10,
        shopCityId: '',
        status: '',
        accountType: '',
        shopName: '',
        fromAppType: '',
        shopContactName: '',
        isMerchant: '',
        onlineStatus: '',
        shopRecommendStatus: '',
        shopContactTel: '',
        userCategoryId: '',
        productCategoryId: '',
        loginAccount: '',
        originSite: 'cn',
        searchPhone: '',
        countryCode: '',
      },
      activateS: -1,
      collapse: false,
      selectLabelShow: false,
      selectDataLabel: [],
      address: '',
      headeNum: [
        { type: '', name: '国内' },
        { type: 'routine', name: '国外' },
      ],
      headeNum1: [
        { type: '', name: '全部' },
        { type: 'routine', name: '未认证' },
        { type: 'routine', name: '个人成功认证' },
        { type: 'routine', name: '企业成功认证' },
        { type: 'routine', name: '个人认证中' },
        { type: 'routine', name: '企业认证中' },
        { type: 'routine', name: '个人认证失败' },
        { type: 'routine', name: '企业认证失败' },
      ],
      headeNum2: [
        { type: '', name: '品牌新机' },
        { type: 'routine', name: '二手贸易' },
        { type: 'routine', name: '纺织工厂' },
      ],
      userLists: [],
      total: 0,
      options1: [{ id: -1, name: '全部' }],
      props1: {
        value: 'id',
        label: 'name',
        children: 'children',
      },
      props2: {
        value: 'zh_id',
        label: 'zh_name',
        children: 'children',
      },
      props3: {
        lazy: true,
        lazyLoad: (node, resolve) => {
          const { level } = node; // node 节点数据
          const nodes = []; // 动态节点
          let type = level == 0 ? '0' : node.value; // 0 代表第一次请求
          that
            .provinceFn(type)
            .then((res) => {
              res.list.map((item) => {
                let area = {
                  value: item.id,
                  label: item.name,
                  leaf: node.level >= 1,
                };
                nodes.push(area);
              });
              resolve(nodes); // 回调
            })
            .catch((error) => {
              console.log(error);
            });
        },
      },
      options: [
        {
          label: '全部',
          value: '-1',
        },
        {
          label: '禁用',
          value: '0',
        },
        {
          label: '启用',
          value: '1',
        },
      ],
      optionsAccountType: [
        { value: -1, label: '所有' },
        { value: 0, label: '普通账户' },
        { value: 1, label: '托管账户' },
      ],
      options3: [
        {
          label: '所有',
          value: '-1',
        },
        {
          label: '国内',
          value: '1',
        },
        {
          label: '国内H5',
          value: '2',
        },
        {
          label: '微信小程序',
          value: '4',
        },
        {
          label: '国内Android',
          value: '8',
        },
        {
          label: '国内IOS',
          value: '16',
        },
        {
          label: '国外PC',
          value: '32',
        },
        {
          label: '国外Android',
          value: '64',
        },
        {
          label: '国外IOS',
          value: '128',
        },
      ],
      options2: [
        {
          label: '全部',
          value: '-1',
        },
        {
          label: '否',
          value: '0',
        },
        {
          label: '是',
          value: '1',
        },
      ],
      options8: [
        {
          label: '全部',
          value: '0',
        },
        {
          label: '在线',
          value: '1',
        },
        {
          label: '1周',
          value: '2',
        },
        {
          label: '1月',
          value: '3',
        },
        {
          label: '永久',
          value: '4',
        },
      ],
      options7: [
        {
          label: '所有',
          value: '-1',
        },
        {
          label: '热门',
          value: '1',
        },
        {
          label: '推荐',
          value: '2',
        },
      ],
      options5: [],
      options6: [],
      options4: [],
    };
  },
  watch: {},
  computed: {},
  async created() {
    console.log(this.imgOssUrl);
    const res = await getUserList({
      page: 1,
      size: 10,
      search_auth_type: -1,
      search_reg_type: -1,
      status: -1,
      origin_site: 'cn',
      user_type: 0,
      from_app_type: -1,
      account_type: -1,
    });

    this.userLists = res.data.data;
    this.total = res.data.total;
  },
  mounted() {
    getRegTypeList().then((res) => {
      let arr = res.data.list;
      this.options1 = [...this.options1, ...arr];
    });

    getUserCategory().then((res) => {
      this.options5 = res.data.list;
    });

    getProductCategory().then((res) => {
      // 请求成功，处理响应数据
      this.options6 = res.data.list;
    });

    getCountryCode().then((res) => {
      this.options4 = res.data.data;
    });
  },
  methods: {
    openSelectLabel() {
      this.selectLabelShow = true;
    },

    async provinceFn(pid) {
      const res = await getProvinceFn({ pid: pid });
      return res.data;
    },

    //地址选择
    handleChange(label) {
      this.address = label;
      console.log(this.address);
    },

    userSearchs() {
      console.log(this.userFrom);
    },
    reset() {
      this.userFrom = {
        userName: '',
        userEmail: '',
        userPhone: '',
        dateTime: '',
        nickName: '',
      };
    },
    pageChange() {},
  },
};
</script>
<style scoped lang="scss">
::v-deep .el-tabs__item {
  height: 54px !important;
  line-height: 54px !important;
}

.picBox {
  display: inline-block;
  cursor: pointer;

  .upLoad {
    width: 58px;
    height: 58px;
    line-height: 58px;
    border: 1px dotted rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.02);
    font-size: 24px;
    font-weight: 500;
  }

  .pictrue {
    width: 60px;
    height: 60px;
    border: 1px dotted rgba(0, 0, 0, 0.1);
    margin-right: 10px;

    img {
      width: 100%;
      height: 100%;
    }
  }
}

.el-card,
.el-message {
  overflow: visible !important;
}

.userFrom {
  ::v-deep .ivu-form-item-content {
    margin-left: 0px !important;
  }
}

.userAlert {
  margin-top: 20px;
}

.userI {
  color: var(--prev-color-primary);
  font-style: normal;
}

img {
  height: 36px;
  display: block;
}

.tabBox2_img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;

  img {
    width: 100%;
    height: 100%;
  }
}
.tabBox_img-box {
  display: flex;
}
.tabBox_img {
  width: 36px;
  height: 36px;
  border-radius: 4px;
  cursor: pointer;

  img {
    width: 100%;
    height: 100%;
  }
}

.tabBox_tit {
  width: 60%;
  font-size: 12px !important;
  margin: 0 2px 0 10px;
  letter-spacing: 1px;
  padding: 5px 0;
  box-sizing: border-box;
}

.modelBox {
  ::v-deep .ivu-modal-body {
    padding: 0 16px 16px 16px !important;
  }
}

.vipName {
  color: #dab176;
}

.listbox {
  ::v-deep .ivu-divider-horizontal {
    margin: 0 !important;
  }
}

.labelInput {
  width: 250px;
  border: 1px solid #dcdee2;
  padding: 0 15px;
  border-radius: 5px;
  min-height: 30px;
  cursor: pointer;
  font-size: 12px;
  .span {
    color: #c5c8ce;
  }

  .ivu-icon-ios-arrow-down {
    font-size: 14px;
    color: #808695;
  }
}

.demo-drawer-footer {
  width: 100%;
  position: absolute;
  bottom: 0;
  left: 0;
  border-top: 1px solid #e8e8e8;
  padding: 10px 16px;
  text-align: right;
  background: #fff;
}
.search-form {
  display: flex;
  justify-content: space-between;
  .search-form-box {
    display: flex;
    flex-wrap: wrap;
    flex: 1;
  }
}
.search-form-sub {
  display: flex;
}
</style>

